package com.open.capacity.talented.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.open.capacity.talented.dao.IndustryDao;
import com.open.capacity.talented.dto.IndustryEditDto;
import com.open.capacity.talented.dto.LayuiDto;
import com.open.capacity.talented.dto.QueryByIndustryIdsDto;
import com.open.capacity.talented.dto.UserIndustryDto;
import com.open.capacity.talented.model.Industry;
import com.open.capacity.talented.service.IndustryService;
import com.open.capacity.talented.vo.TalentedByIndustryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class IndustryServiceImpl implements IndustryService {
    @Autowired
    IndustryDao industryDao;

    @Override
    public PageInfo<UserIndustryDto> queryTalentedWithIndustryByPageAndLimit(LayuiDto dto, Integer enabled) {
        PageHelper.startPage(dto.getPage(),dto.getLimit());
        List<UserIndustryDto> userIndustryDtos = industryDao.queryTalentedWithIndustryByPageAndLimit(enabled);
        PageInfo<UserIndustryDto> pageInfo = new PageInfo(userIndustryDtos);
        return pageInfo;
    }

    @Override
    public List<Industry> queryIndustryByParentId(Long parentId) {
        return industryDao.queryIndustryByParentId(parentId);
    }

    @Override
    public List<TalentedByIndustryVo> queryTalentedByIndustryIds(QueryByIndustryIdsDto dto) {
        return industryDao.queryTalentedByIndustryIds(dto);
    }

    @Override
    public List queryIndustryListByIds(List<Long> ids) {
        return industryDao.queryIndustryByIds(ids);
    }

    @Override
    public List<Long> queryIndustryIdsByUserId(Long id) {
        return industryDao.queryIndustryIdsByUserId(id);
    }

    @Override
    public List queryAllIndustryList() {
        return industryDao.queryAllIndustryList();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean changeTalentedIndustryByUserId(IndustryEditDto dto) {
        boolean delflag = industryDao.deleteAllIndustryByUserId(dto.getUserId())>=0;
        if(dto.getIndustryIds().size() == 0){
            return delflag;
        }
        return industryDao.insertIndustrysByUserId(dto) >0;
    }

}
